﻿using Streetlight.Store.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Streetlight.Store.MvcApplication.Controllers
{
    public class ProductCategoriesController : StoreController
    {
        public ActionResult Index()
        {
            List<ProductCategory> model = TransactionManager.Products.ListAllCategories();

            return View("List", model);
        }

        public ActionResult List()
        {
            List<ProductCategory> model = TransactionManager.Products.ListAllCategories();

            return View(model);
        }

        public ActionResult Create()
        {
            ProductCategory model = new ProductCategory();

            return View(model);
        }

        [HttpPost]
        public ActionResult Create(ProductCategory model)
        {
            if (ModelState.IsValid)
            {
                TransactionManager.Products.CreateNewCategory(model);

                return RedirectToAction("Edit", new { id = model.Id });
            }

            return View(model);
        }

        public ActionResult Edit(string id)
        {
            ProductCategory model = TransactionManager.Products.GetCategory(id);

            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(ProductCategory model)
        {
            if (ModelState.IsValid)
            {
                TransactionManager.Products.SaveCategory(model);
            }

            return View(model);
        }
    }
}
